home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / jikes.lha / jikes-1.11 / src / jcl / jcl_class.cpp < prev    next >
C/C++ Source or Header  |  1999-11-04  |  7KB  |  190 lines

  1. // $Id: jcl_class.cpp,v 1.1 1999/11/04 18:48:03 shields Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #include <iostream.h>
  11. #include <string.h>
  12. #include "jcl_class.h"
  13. #include "jcl_long.h"
  14.  
  15.  
  16. #ifdef TEST
  17.         //virtual
  18.                         void ClassFile::print() {
  19.                 int i;
  20.                 cout << "magic " << hex << magic << dec
  21.                          << "  major_version " << major_version
  22.                          << "  minor_version " << minor_version << "\n";
  23.                 AccessFlags::print();
  24. //              access_flags.print(constant_pool);
  25.                 cout << "\n";
  26.                 cout << "  this_class " << this_class << "  super_class " << super_class <<"\n";
  27.                 cout << "  constant_pool: " << constant_pool.length() << "\n";
  28.                 for (i=1;i<constant_pool.length();i++) {
  29.                         cout << "  " << i << "  ";
  30.                         constant_pool[i]->print(constant_pool);
  31.             if (constant_pool[i] -> tag == CONSTANT_Long ||
  32.                 constant_pool[i] -> tag == CONSTANT_Double) {
  33.                 i++;; // skip the next entry for eight-byte constants
  34.             }
  35.                 }
  36.                 cout << "  interfaces " << interfaces.length() <<": ";
  37.                 for (i=0;i<interfaces.length();i++) cout << "  " << (int) interfaces[i];
  38.                 cout <<"\n";
  39.                 for (i=0;i<fields.length();i++) {
  40.                         cout << "field " << i << "\n";
  41.                         fields[i].print(constant_pool);
  42.                 }
  43.                 cout << "methods length " << methods.length() << "\n";
  44.                 for (i=0;i<methods.length();i++) {
  45.                         cout << "method " << i << "\n";
  46.                         methods[i].print(constant_pool);
  47.                 }
  48.                 for (i=0;i<attributes.length();i++) {
  49.                         cout << "attribute " << i << "\n";
  50.                         attributes[i]->print(constant_pool);
  51.                 }
  52.                 cout << "\n";
  53.         } 
  54. //virtual
  55.    void ClassFile::print_const(DynamicArray<cp_info *>& constant_pool,int i) 
  56. {
  57.  
  58. // return string identifying constant pool entry
  59.         if (i<1 || i > constant_pool.length()) {
  60.                 cout << " constant_pool index out of range" << i << "\n:";
  61.                 return;
  62.         }
  63.         else if (constant_pool[i]==NULL) { // if this entry to be skipped
  64.       cout << "NO-SUCH-ENTRY";
  65.       return;
  66.         }
  67.         // save this code if want brief form
  68.         if (i<0 | i > constant_pool.length()) {
  69.                 cout << "illegal cp index (" << i << ")" ;
  70.                 return;
  71.         }
  72.         constant_pool[i]->describe(constant_pool);
  73. }
  74.  
  75.  void ClassFile::print_const(int i) 
  76. {
  77.  
  78. // return string identifying constant pool entry
  79.         if (i<1 || i > constant_pool.length()) {
  80.                 cout << " constant_pool index out of range" << i << "\n:";
  81.                 return;
  82.         }
  83.         else if (constant_pool[i]==NULL) { // if this entry to be skipped
  84.       cout << "NO-SUCH-ENTRY";
  85.       return;
  86.         }
  87.         // save this code if want brief form
  88.         if (i<0 | i > constant_pool.length()) {
  89.                 cout << "illegal cp index (" << i << ")" ;
  90.                 return;
  91.         }
  92.         cp_info *cp=constant_pool[i];
  93.     switch(cp->tag) {
  94.         case ClassFile::CONSTANT_Class:{
  95.             CONSTANT_Class_info * ccp = (CONSTANT_Class_info *) cp;
  96.             cout << " Class:";
  97.                 print_const(ccp->name_index);
  98.             break;
  99.             }
  100.         case ClassFile::CONSTANT_Fieldref: {
  101.             CONSTANT_Fieldref_info * ccp = (CONSTANT_Fieldref_info *) cp;
  102.             cout << "Field:" << ccp->class_index;
  103.             print_const(ccp->class_index);
  104.             cout << ".";
  105.             print_const(ccp->name_and_type_index);
  106.             break;
  107.             }
  108.         case ClassFile::CONSTANT_Methodref: {
  109.             CONSTANT_Methodref_info * ccp = (CONSTANT_Methodref_info *) cp;
  110.             cout << "Methodref:";
  111.             print_const(ccp->class_index);
  112.             cout << ".";
  113.             print_const(ccp->name_and_type_index);
  114.             break;
  115.             }
  116.         case ClassFile::CONSTANT_InterfaceMethodref: {
  117.             CONSTANT_InterfaceMethodref_info * ccp = (CONSTANT_InterfaceMethodref_info *) cp;
  118.             cout << "InterfaceMethodref: " ;
  119.             print_const(ccp->class_index);
  120.             cout << ".";
  121.             print_const(ccp->name_and_type_index);
  122.             break;
  123.             }
  124.         case ClassFile::CONSTANT_String: {
  125.             CONSTANT_String_info * ccp = (CONSTANT_String_info *) cp;
  126. //          cout << " U:";
  127.             print_const(ccp->string_index);
  128.             break; 
  129.             }
  130.         case ClassFile::CONSTANT_Integer: {
  131.             CONSTANT_Integer_info * ccp = (CONSTANT_Integer_info *) cp;
  132.             int *ip;
  133.             ip = (int *) & ccp->bytes;
  134.             cout << "Integer:";
  135.             cout << *ip;
  136.             break;
  137.             }
  138.         case ClassFile::CONSTANT_Float: {
  139.             CONSTANT_Float_info * ccp = (CONSTANT_Float_info *) cp;
  140.             float *fp;
  141.             fp = (float *) &ccp->bytes;
  142.             cout << "Float:";
  143.                 cout<< *fp;
  144.             break;
  145.             }
  146.         case ClassFile::CONSTANT_Long: {
  147.             CONSTANT_Long_info * ccp = (CONSTANT_Long_info *) cp;
  148.             char  longstr[65];
  149.             cout << "Long:";
  150.             Long(ccp->high_bytes, ccp->low_bytes).String(longstr);
  151.             cout << longstr;
  152.             print_const(constant_pool,i);
  153.             break;
  154.             }
  155.         case ClassFile::CONSTANT_Double: {
  156.             CONSTANT_Double_info * ccp = (CONSTANT_Double_info *) cp;
  157.             Long lval = Long(ccp->high_bytes,ccp->low_bytes);
  158.             cout << "Double:";
  159.             cout << lval.DoubleView();
  160.             print_const(constant_pool,i);
  161.             break;
  162.             }
  163.         case ClassFile::CONSTANT_NameAndType: {
  164.             CONSTANT_NameAndType_info * ccp = (CONSTANT_NameAndType_info *) cp;
  165.             cout << " NameAndType " ;
  166.             print_const(ccp->name_index);
  167.             cout << " " ;
  168.             print_const(ccp->descriptor_index);
  169.             break;
  170.             }
  171.         case ClassFile::CONSTANT_Utf8: {
  172.             CONSTANT_Utf8_info * ccp = (CONSTANT_Utf8_info *) cp;
  173.                 int i;
  174.                 cout << " \"";
  175.                 for (i=0;i<ccp->length();i++) {
  176.                         Unicode::Cout(ccp->bytes[i]);
  177.                 }
  178.                 cout << "\"";
  179.             break;
  180.             }
  181.                 
  182.         default:
  183.             cout << "uknown constant kind " << cp->tag  << " for pool index " << i << "\n";
  184.             cerr << "uknown constant kind " << cp->tag  << " for pool index " << i << "\n";
  185.         }
  186.  
  187. }
  188.  
  189. #endif
  190.